﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.PM.PO;

namespace UFIDA.U9C.Cust.ZL.API.DTO.SRMDTO
{
    /// <summary>
    /// U9C采购订单转SRM 格式
    /// </summary>
    public class SRMPO
    {
        public SRMPO(UFIDA.U9.PM.PO.PurchaseOrder PO)
        {
            exe_pur_order_b = new exe_pur_order_b(PO);
            exe_pur_order_address_b = new exe_pur_order_address_b(PO);

            exe_pur_order_dtl_b = new List<exe_pur_order_dtl_b>();
            foreach (POLine item in PO.POLines)
            {
                exe_pur_order_dtl_b.Add(new exe_pur_order_dtl_b(item));
            }
        }
        public exe_pur_order_b exe_pur_order_b = new exe_pur_order_b();
        public exe_pur_order_address_b exe_pur_order_address_b = new exe_pur_order_address_b();
        public List<exe_pur_order_dtl_b> exe_pur_order_dtl_b = new List<exe_pur_order_dtl_b>();
        public List<exe_order_dtl_condition_b> exe_order_dtl_condition_b = new List<exe_order_dtl_condition_b>();
        /// <summary>
        /// 采购订单阶段基本信息 默认值即可
        /// </summary>
        public exe_pur_order_stage_inf_b exe_pur_order_stage_inf_b = new exe_pur_order_stage_inf_b();


        public List<object> exe_order_dtl_subject_b = new List<object>();
        public List<object> exe_pur_order_expense_b = new List<object>();
        public List<object> exe_pur_order_stage_b = new List<object>();
        public List<object> exe_order_dtl_component_b = new List<object>();

    }

    /// <summary>
    /// srm采购订单抬头
    /// </summary>
    public class exe_pur_order_b
    {
        public exe_pur_order_b() { }
        public exe_pur_order_b(UFIDA.U9.PM.PO.PurchaseOrder po)
        {
            this.erp_no = po.DocNo;
            this.order_date = po.BusinessDate.ToString("yyyyMMdd");
            this.order_type_code = po.DocumentType.Code;
            this.order_type_code_show = po.DocumentType.Name;
            this.supplier_code = po?.Supplier?.Code;
            this.supplier_name = po?.Supplier?.Name;
            this.supplier_code_show = po?.Supplier?.Name;
            this.pur_org_code = po.Org.Code;
            this.pur_org_code_show = po.Org.Name;
            this.pur_group_code = "001";
            this.pur_group_code_show = "生产型物料采购组";
            this.company_code = po.Org.Code;
            this.company_code_show = po.Org.Name;
            string currycode = po?.TC?.Code;
            string curryname = po?.TC?.Name;
            this.corporate_currency_code = currycode;
            this.corporate_currency_code_show = curryname;
            this.order_currency_code = currycode;
            this.order_currency_code_show = curryname;
            this.exchange_rate = po.TaxRate.ToString();
            this.invoice_square = po.Supplier?.Supplier?.Code;
            this.invoice_square_show = po.Supplier?.Supplier?.Name;
            this.online_order_flag = 1;
            this.price_tax_flag = po.IsPriceIncludeTax ? 1 : 0;


        }
        /// <summary>
        /// 订单号
        /// </summary>
        public string no { get; set; }
        /// <summary>
        /// ERP订单号
        /// </summary>
        public string erp_no { get; set; }
        /// <summary>
        /// 订单日期 yyyyMMdd格式
        /// </summary>
        public string order_date { get; set; }
        /// <summary>
        /// 订单类型
        /// </summary>
        public string order_type_code { get; set; }
        /// <summary>
        /// 订单类型描述
        /// </summary>
        public string order_type_code_show { get; set; }
        /// <summary>
        /// 供应商编号
        /// </summary>
        public string supplier_code { get; set; }
        /// <summary>
        /// 供应商编号描述
        /// </summary>
        public string supplier_code_show { get; set; }
        /// <summary>
        /// 供应商名称
        /// </summary>
        public string supplier_name { get; set; }
        /// <summary>
        /// 采购组织编号
        /// </summary>
        public string pur_org_code { get; set; }
        /// <summary>
        /// 采购组织名称
        /// </summary>
        public string pur_org_code_show { get; set; }
        /// <summary>
        /// 采购组编号
        /// </summary>
        public string pur_group_code { get; set; }
        /// <summary>
        /// 采购组名称
        /// </summary>
        public string pur_group_code_show { get; set; }
        /// <summary>
        /// 公司编号
        /// </summary>
        public string company_code { get; set; }
        /// <summary>
        /// 公司名称
        /// </summary>
        public string company_code_show { get; set; }
        /// <summary>
        /// 公司本位币
        /// </summary>
        public string corporate_currency_code { get; set; }
        /// <summary>
        /// 公司本位币名称
        /// </summary>
        public string corporate_currency_code_show { get; set; }
        /// <summary>
        /// 订单货币
        /// </summary>
        public string order_currency_code { get; set; }
        /// <summary>
        /// 订单货币名称
        /// </summary>
        public string order_currency_code_show { get; set; }
        /// <summary>
        /// 汇率
        /// </summary>
        public string exchange_rate { get; set; }
        /// <summary>
        /// 开票方编号
        /// </summary>
        public string invoice_square { get; set; }
        /// <summary>
        /// 开票方名称
        /// </summary>
        public string invoice_square_show { get; set; }
        /// <summary>
        /// 供应商在线接单true传1，false传0
        /// </summary>
        public int online_order_flag { get; set; }
        /// <summary>
        /// 价格含税true传1，false传0
        /// </summary>
        public int price_tax_flag { get; set; }


    }

    /// <summary>
    /// 采购订单地址
    /// </summary>
    public class exe_pur_order_address_b
    {
        public exe_pur_order_address_b() { }
        public exe_pur_order_address_b(UFIDA.U9.PM.PO.PurchaseOrder po)
        {
            this.addres_consistent_flag = 1;
            U9.Base.Location.Location adress = po.Org?.Contact?.DefaultLocation;

            this.country_id = adress?.Country?.Code;
            this.country_id_show = adress?.Country?.Name;
            this.province_id = adress?.Province?.Code;
            this.province_id_show = adress?.Province?.Name;
            this.city_id = adress?.City?.Code;
            this.city_id_show = adress?.City?.Name;
            this.address = adress.Address1;
            this.contact = po?.PurOper?.Contact?.Name;
            this.contact_way = po?.PurOper?.Contact?.DefaultMobilNum;

        }
        /// <summary>
        /// 明细地址是否与抬头一致true传1，false传0
        /// </summary>
        public int addres_consistent_flag { get; set; }
        /// <summary>
        /// 国家编号
        /// </summary>
        public string country_id { get; set; }
        /// <summary>
        /// 国家名称
        /// </summary>
        public string country_id_show { get; set; }
        /// <summary>
        /// 省份编号
        /// </summary>
        public string province_id { get; set; }
        /// <summary>
        /// 省份名称
        /// </summary>
        public string province_id_show { get; set; }
        /// <summary>
        /// 城市编号
        /// </summary>
        public string city_id { get; set; }
        /// <summary>
        /// 城市名称
        /// </summary>
        public string city_id_show { get; set; }
        /// <summary>
        /// 详细地址
        /// </summary>
        public string address { get; set; }
        /// <summary>
        /// 联系人
        /// </summary>
        public string contact { get; set; }
        /// <summary>
        /// 联系方式
        /// </summary>
        public string contact_way { get; set; }

    }

    /// <summary>
    /// 其他费用
    /// </summary>
    public class exe_pur_order_expense_b
    {
        /// <summary>
        /// 行项目号
        /// </summary>
        public string item_no { get; set; }
        /// <summary>
        /// 条件类型
        /// </summary>
        public string condition_type_dk { get; set; }
        /// <summary>
        /// 条件类型类别
        /// </summary>
        public string condition_type_category { get; set; }
        /// <summary>
        /// 金额
        /// </summary>
        public string amount { get; set; }
        /// <summary>
        /// 货币
        /// </summary>
        public string currency_code { get; set; }
        /// <summary>
        /// 货币名称
        /// </summary>
        public string currency_code_show { get; set; }
        /// <summary>
        /// 价格单位
        /// </summary>
        public string unit_price { get; set; }
        /// <summary>
        /// 单位
        /// </summary>
        public string unit_code { get; set; }
        /// <summary>
        /// 单位名称
        /// </summary>
        public string unit_code_show { get; set; }
        /// <summary>
        /// 供应商编号
        /// </summary>
        public string supplier_code { get; set; }
        /// <summary>
        /// 供应商名称
        /// </summary>
        public string supplier_code_show { get; set; }
        /// <summary>
        /// 删除标记true传1，false传0
        /// </summary>
        public int deletion_flag { get; set; }

    }
    /// <summary>
    /// 采购订单阶段基本信息
    /// </summary>
    public class exe_pur_order_stage_inf_b
    {
        public exe_pur_order_stage_inf_b()
        {
            this.confirmation_payment_flag = 0;
        }
        /// <summary>
        /// 按阶段确认和付款true传1，false传0
        /// </summary>
        public int confirmation_payment_flag { get; set; }

    }
    /// <summary>
    /// 采购订单阶段
    /// </summary>
    public class exe_pur_order_stage_b
    {
        /// <summary>
        /// 行项目号
        /// </summary>
        public string item_no { get; set; }
        /// <summary>
        /// 阶段名称
        /// </summary>
        public string stage_name { get; set; }
        /// <summary>
        /// 阶段说明
        /// </summary>
        public string stage_remark { get; set; }
        /// <summary>
        /// 阶段确认类型
        /// </summary>
        public string confirm_type_dk { get; set; }
        /// <summary>
        /// 是否需付款
        /// </summary>
        public int require_payment_flag { get; set; }
        /// <summary>
        /// 付款方式
        /// </summary>
        public string payment_method_dk { get; set; }
        /// <summary>
        /// 付款说明
        /// </summary>
        public string payment_remark { get; set; }
        /// <summary>
        /// 付款比例
        /// </summary>
        public string payment_scale { get; set; }
        /// <summary>
        /// 付款金额
        /// </summary>
        public string payment_amount { get; set; }
    }
    /// <summary>
    /// 采购订单明细
    /// </summary>
    public class exe_pur_order_dtl_b
    {
        public exe_pur_order_dtl_b(UFIDA.U9.PM.PO.POLine po)
        {
            this.item_no = po.DocLineNo.ToString();
            this.material_code = po.ItemInfo.ItemCode;
            this.material_code_show = po.ItemInfo.ItemCode;
            this.material_name = po.ItemInfo.ItemName;

            this.material_category_code = po.ItemInfo?.ItemID?.MainItemCategory?.Code;
            this.material_category_code_show = po.ItemInfo?.ItemID?.MainItemCategory?.Name;
            this.plant_code = po.PurchaseOrder.Org.Code;
            this.plant_code_show = po.PurchaseOrder.Org.Name;
            if (po.POShiplines.Count > 0)
            {
                this.storage_location_code = po.POShiplines[0]?.Wh?.Code;
                this.storage_location_code_show = po.POShiplines[0]?.Wh?.Name;
                this.delivery_date = po.POShiplines[0].DeliveryDate.ToString("yyyyMMdd");
            }
            this.purchase_request_no = po.SrcDocInfo?.SrcDocNo;
            this.purchase_request_item_no = po.SrcDocInfo?.SrcDocLineNo.ToString();
            this.qty = po.PurQtyTU;
            this.unit_code = po?.TradeUOM?.Code;
            this.unit_code_show = po?.TradeUOM?.Name;
            this.price_unit_code = po?.TradeUOM?.Code;
            this.price_unit_code_show = po?.TradeUOM?.Name;
            this.to_ou_molecular = 1;
            this.to_ou_denominator = 1;
            this.basic_unit_code = po?.TradeUOM?.Code;
            this.basic_unit_code_show = po?.TradeUOM?.Name;


            this.need_the_goods_flag = 1;
            this.delivered_flag = 0;
            this.return_flag = 0;
            this.invoice_verif_flag = 0;
            this.suspended_flag = 0;
            this.free_flag = po.IsPresent ? 1 : 0;
            this.temporary_valuation_flag = 0;
            this.urgent_flag = 0;
            this.deletion_flag = 0;
            this.price = po.FinallyPriceTC;//最终价(原币)
            this.price_unit_qty = 1;
            this.tax_code = po?.TaxSchedule?.Code;
            this.tax_rate = po.TaxRate;
            this.amount = po.TotalMnyAC;
            this.mainKey = po.DocLineNo.ToString();
            this.to_bu_denominator = "1";
            this.to_bu_molecular = "1";

            this.address = po.PurchaseOrder.Org?.Contact?.DefaultLocation?.Address1;
            this.contact = po.PurchaseOrder?.PurOper?.Name;
            this.contact_way = po.PurchaseOrder?.PurOper?.Contact.DefaultMobilNum;


        }
        /// <summary>
        /// 行项目号
        /// </summary>
        public string item_no { get; set; }
        /// <summary>
        /// 物料编号
        /// </summary>
        public string material_code { get; set; }
        /// <summary>
        /// 物料编号描述
        /// </summary>
        public string material_code_show { get; set; }
        /// <summary>
        /// 物料名称
        /// </summary>
        public string material_name { get; set; }
        /// <summary>
        /// 科目分配类别
        /// </summary>
        //public string subject_allocation_type_dk { get; set; }
        /// <summary>
        /// 项目类别
        /// </summary>
        //public string project_category_dk { get; set; }
        /// <summary>
        /// 物料品类
        /// </summary>
        public string material_category_code { get; set; }
        /// <summary>
        /// 物料品类描述
        /// </summary>
        public string material_category_code_show { get; set; }
        /// <summary>
        /// 工厂编号
        /// </summary>
        public string plant_code { get; set; }
        /// <summary>
        /// 工厂名称
        /// </summary>
        public string plant_code_show { get; set; }
        /// <summary>
        /// 库存地点编号
        /// </summary>
        public string storage_location_code { get; set; }
        /// <summary>
        /// 库存地点名称
        /// </summary>
        public string storage_location_code_show { get; set; }
        /// <summary>
        /// 交货日期 yyyyMMdd格式
        /// </summary>
        public string delivery_date { get; set; }
        /// <summary>
        /// 批次
        /// </summary>
        //public string batch { get; set; }
        /// <summary>
        /// 采购申请编号
        /// </summary>
        public string purchase_request_no { get; set; }
        /// <summary>
        /// 采购申请行号
        /// </summary>
        public string purchase_request_item_no { get; set; }
        /// <summary>
        /// 订单数量
        /// </summary>
        public decimal qty { get; set; }
        /// <summary>
        /// 订单单位
        /// </summary>
        public string unit_code { get; set; }
        /// <summary>
        /// 订单单位名称
        /// </summary>
        public string unit_code_show { get; set; }
        /// <summary>
        /// 订单定价单位
        /// </summary>
        public string price_unit_code { get; set; }
        /// <summary>
        /// 订单定价单位名称
        /// </summary>
        public string price_unit_code_show { get; set; }
        /// <summary>
        /// 订单定价单位转订单单位分子
        /// </summary>
        public int to_ou_molecular { get; set; }
        /// <summary>
        /// 订单定价单位转订单单位分母
        /// </summary>
        public int to_ou_denominator { get; set; }
        /// <summary>
        /// 基本单位
        /// </summary>
        public string basic_unit_code { get; set; }
        /// <summary>
        /// 基本单位名称
        /// </summary>
        public string basic_unit_code_show { get; set; }
        /// <summary>
        /// 订单单位转基本单位分子
        /// </summary>
        public string to_bu_molecular { get; set; }
        /// <summary>
        /// 订单单位转基本单位分母
        /// </summary>
        public string to_bu_denominator { get; set; }
        /// <summary>
        /// 过量交货限度（容差）
        /// </summary>
        //public string alw { get; set; }
        ///// <summary>
        ///// 交货不足允许比例
        ///// </summary>
        //public string underdelivery_ratio { get; set; }
        /// <summary>
        /// 需要收货
        /// </summary>
        public int need_the_goods_flag { get; set; }
        /// <summary>
        /// 交货已完成
        /// </summary>
        public int delivered_flag { get; set; }
        /// <summary>
        /// 退货项目
        /// </summary>
        public int return_flag { get; set; }
        /// <summary>
        /// 基于收货的发票校验
        /// </summary>
        public int invoice_verif_flag { get; set; }
        /// <summary>
        /// 暂停收货
        /// </summary>
        public int suspended_flag { get; set; }
        /// <summary>
        /// 免费
        /// </summary>
        public int free_flag { get; set; }
        /// <summary>
        /// 暂估价
        /// </summary>
        public int temporary_valuation_flag { get; set; }
        /// <summary>
        /// 加急
        /// </summary>
        public int urgent_flag { get; set; }
        /// <summary>
        /// 删除标记
        /// </summary>
        public int deletion_flag { get; set; }
        /// <summary>
        /// 价格
        /// </summary>
        public decimal price { get; set; }
        /// <summary>
        /// 价格单位
        /// </summary>
        public decimal price_unit_qty { get; set; }
        /// <summary>
        /// 税码
        /// </summary>
        public string tax_code { get; set; }
        /// <summary>
        /// 税率
        /// </summary>
        public decimal tax_rate { get; set; }
        /// <summary>
        /// 金额
        /// </summary>
        public decimal amount { get; set; }
        /// <summary>
        /// 未税单价
        /// </summary>
        public string untaxed_unit_price { get; set; }
        /// <summary>
        /// 含税单价
        /// </summary>
        public string taxed_unit_price { get; set; }
        /// <summary>
        /// 国家编号
        /// </summary>
        public string country_id { get; set; }
        /// <summary>
        /// 国家名称
        /// </summary>
        public string country_id_show { get; set; }
        /// <summary>
        /// 省份编号
        /// </summary>
        public string province_id { get; set; }
        /// <summary>
        /// 省份名称
        /// </summary>
        public string province_id_show { get; set; }
        /// <summary>
        /// 城市编号
        /// </summary>
        public string city_id { get; set; }
        /// <summary>
        /// 城市名称
        /// </summary>
        public string city_id_show { get; set; }
        /// <summary>
        /// 详细地址
        /// </summary>
        public string address { get; set; }
        /// <summary>
        /// 联系人
        /// </summary>
        public string contact { get; set; }
        /// <summary>
        /// 联系方式
        /// </summary>
        public string contact_way { get; set; }
        /// <summary>
        /// 明细行标识KEY
        /// </summary>
        public string mainKey { get; set; }

    }
    /// <summary>
    /// 采购订单明细其他价格
    /// </summary>
    public class exe_order_dtl_condition_b
    {
        public exe_order_dtl_condition_b(UFIDA.U9.PM.PO.POLine po)
        {

        }
        /// <summary>
        /// 行项目号
        /// </summary>
        public string item_no { get; set; }
        /// <summary>
        /// 订单明细行key
        /// </summary>
        public string parentKey { get; set; }
        /// <summary>
        /// 条件类型
        /// </summary>
        public string condition_type_dk { get; set; }
        /// <summary>
        /// 条件类型类别
        /// </summary>
        public string condition_type_category { get; set; }
        /// <summary>
        /// 供应商编号
        /// </summary>
        public string supplier_code { get; set; }
        /// <summary>
        /// 供应商名称
        /// </summary>
        public string supplier_code_show { get; set; }
        /// <summary>
        /// 价格
        /// </summary>
        public string price { get; set; }
        /// <summary>
        /// 货币
        /// </summary>
        public string currency_code { get; set; }
        /// <summary>
        /// 货币名称
        /// </summary>
        public string currency_code_show { get; set; }
        /// <summary>
        /// 价格单位
        /// </summary>
        public string unit_price { get; set; }
        /// <summary>
        /// 单位
        /// </summary>
        public string unit_code { get; set; }
        /// <summary>
        /// 单位名称
        /// </summary>
        public string unit_code_show { get; set; }
        /// <summary>
        /// 删除标记
        /// </summary>
        public int deletion_flag { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string remark { get; set; }

    }
    /// <summary>
    /// 采购订单明细行科目
    /// </summary>
    public class exe_order_dtl_subject_b
    {
        /// <summary>
        /// 行项目号
        /// </summary>
        public string item_no { get; set; }
        /// <summary>
        /// 订单明细行key
        /// </summary>
        public string parentKey { get; set; }
        /// <summary>
        /// 总账科目
        /// </summary>
        public string gl_account_no { get; set; }
        /// <summary>
        /// 总账科目描述
        /// </summary>
        public string gl_account_no_show { get; set; }
        /// <summary>
        /// 成本中心
        /// </summary>
        public string cost_center_no { get; set; }
        /// <summary>
        /// 成本中心描述
        /// </summary>
        public string cost_center_no_show { get; set; }
        /// <summary>
        /// 内部订单号
        /// </summary>
        public string inner_order_no { get; set; }
        /// <summary>
        /// 内部订单号描述
        /// </summary>
        public string inner_order_no_show { get; set; }
        /// <summary>
        /// 销售订单号
        /// </summary>
        public string sales_order_no { get; set; }
        /// <summary>
        /// 销售订单号描述
        /// </summary>
        public string sales_order_no_show { get; set; }
        /// <summary>
        /// 销售订单行项目号
        /// </summary>
        public string sales_order_item_no { get; set; }
        /// <summary>
        /// 销售计划行号
        /// </summary>
        public string sales_order_plan_no { get; set; }
        /// <summary>
        /// 资产编号
        /// </summary>
        public string asset_no { get; set; }
        /// <summary>
        /// 资产号描述
        /// </summary>
        public string asset_no_show { get; set; }
        /// <summary>
        /// 次级资产编号
        /// </summary>
        public string sec_asset_no { get; set; }
        /// <summary>
        /// 删除标记
        /// </summary>
        public int deletion_flag { get; set; }

    }
    /// <summary>
    /// 采购订单明细行组件
    /// </summary>
    public class exe_order_dtl_component_b
    {
        /// <summary>
        /// 行项目号
        /// </summary>
        public string item_no { get; set; }
        /// <summary>
        /// 订单明细行key
        /// </summary>
        public string parentKey { get; set; }
        /// <summary>
        /// 物料编号
        /// </summary>
        public string material_code { get; set; }
        /// <summary>
        /// 物料名称
        /// </summary>
        public string material_code_show { get; set; }
        /// <summary>
        /// 需求数量
        /// </summary>
        public string required_qty { get; set; }
        /// <summary>
        /// 条目单位
        /// </summary>
        public string entry_unit_code { get; set; }
        /// <summary>
        /// 条目单位名称
        /// </summary>
        public string entry_unit_code_show { get; set; }
        /// <summary>
        /// 工厂
        /// </summary>
        public string plant_code { get; set; }
        /// <summary>
        /// 工厂名称
        /// </summary>
        public string plant_code_show { get; set; }
        /// <summary>
        /// 固定数量
        /// </summary>
        public int qty_fixed_flag { get; set; }
        /// <summary>
        /// 生产仓储地点
        /// </summary>
        public string production_storage_code { get; set; }
        /// <summary>
        /// 生产仓储地点名称
        /// </summary>
        public string production_storage_code_show { get; set; }
        /// <summary>
        /// 供应区域
        /// </summary>
        public string supply_area { get; set; }
        /// <summary>
        /// 需求日期yyyyMMdd格式
        /// </summary>
        public string required_date { get; set; }
        /// <summary>
        /// 批次
        /// </summary>
        public string batch { get; set; }
        /// <summary>
        /// 基本计量单位
        /// </summary>
        public string base_unit_code { get; set; }
        /// <summary>
        /// 基本计量单位名称
        /// </summary>
        public string base_unit_code_show { get; set; }
        /// <summary>
        /// 删除标记
        /// </summary>
        public int deletion_flag { get; set; }

    }
}
